home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / src / bouncebk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-03  |  3.5 KB  |  133 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: bouncebk.c,v 5.2 1993/02/03 19:06:31 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.2 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1988-1992 USENET Community Trust
  8.  *             Copyright (c) 1986,1987 Dave Taylor
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log: bouncebk.c,v $
  17.  * Revision 5.2  1993/02/03  19:06:31  syd
  18.  * Remove extra strchr/strcat/strcpy et al declarations
  19.  * From: Syd
  20.  *
  21.  * Revision 5.1  1992/10/03  22:58:40  syd
  22.  * Initial checkin as of 2.4 Release at PL0
  23.  *
  24.  *
  25.  ******************************************************************************/
  26.  
  27. /** This set of routines implement the bounceback feature of the mailer.
  28.     This feature allows mail greater than 'n' hops away (n specified by
  29.     the user) to have a 'cc' to the user through the remote machine.  
  30.  
  31.     Due to the vagaries of the Internet addressing (uucp -> internet -> uucp)
  32.     this will NOT generate bounceback copies with mail to an internet host!
  33.  
  34. **/
  35.  
  36. #include "headers.h"
  37.  
  38. char *bounce_off_remote();        /* forward declaration */
  39.  
  40. int
  41. uucp_hops(to)
  42. register char *to;
  43. {    
  44.     /** Given the entire "To:" list, return the number of hops in the
  45.         first address (a hop = a '!') or ZERO iff the address is to a
  46.           non uucp address.
  47.     **/
  48.  
  49.     register int hopcount = 0, len;
  50.  
  51.     while (*to) {
  52.       len = len_next_part(to);
  53.       if (len == 1) {
  54.         if (whitespace(*to))
  55.           break;
  56.         
  57.         if (*to == '!')
  58.           hopcount++;
  59.         else if (*to == '@' || *to == '%' || *to == ':')
  60.           return(0);    /* don't continue! */
  61.       }
  62.       to += len;
  63.     }
  64.  
  65.     return(hopcount);
  66. }
  67.     
  68. char *bounce_off_remote(to)
  69. register char *to;
  70. {
  71.     /** Return an address suitable for framing (no, that's not it...)
  72.         Er, suitable for including in a 'cc' line so that it ends up
  73.         with the bounceback address.  The method is to take the first 
  74.         address in the To: entry and break it into machines, then 
  75.         build a message up from that.  For example, consider the
  76.         following address:
  77.             a!b!c!d!e!joe
  78.         the bounceback address would be;
  79.             a!b!c!d!e!d!c!b!a!ourmachine!ourname
  80.         simple, eh?
  81.     **/
  82.  
  83.     static char address[LONG_STRING];    /* BEEG address buffer! */
  84.  
  85.     char   host[MAX_HOPS][NLEN];    /* for breaking up addr */
  86.     register int hostcount = 0, hindex = 0, iindex, len;
  87.  
  88.     while (*to) {
  89.       len = len_next_part(to);
  90.       if (len == 1) {
  91.         if (whitespace(*to))
  92.           break;
  93.         
  94.         if (*to == '!') {
  95.           host[hostcount][hindex] = '\0';
  96.           hostcount++;
  97.           hindex = 0;
  98.         } else 
  99.           host[hostcount][hindex++] = *to++;
  100.       } else {
  101.         while (--len >= 0)
  102.           host[hostcount][hindex++] = *to++;
  103.       }
  104.     }
  105.  
  106.     /* we have hostcount hosts... */
  107.  
  108.     strcpy(address, host[0]);    /* initialize it! */
  109.  
  110.     for (iindex=1; iindex < hostcount; iindex++) {
  111.       strcat(address, "!");
  112.       strcat(address, host[iindex]);
  113.     }
  114.     
  115.     /* and now the same thing backwards... */
  116.  
  117.     for (iindex = hostcount -2; iindex > -1; iindex--) {
  118.       strcat(address, "!");
  119.       strcat(address, host[iindex]);
  120.     }
  121.  
  122.     /* and finally, let's tack on our machine and login name */
  123.  
  124.     strcat(address, "!");
  125.     strcat(address, hostname);
  126.     strcat(address, "!");
  127.     strcat(address, username);
  128.  
  129.     /* and we're done!! */
  130.  
  131.     return( (char *) address );
  132. }
  133.